package sevelet;

import PageBean.PageBean;
import pojo.Brand;
import service.BrandService;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.List;

@WebServlet(name = "SelectAllServlet", value = "/selectAll")
public class SelectAllServlet extends HttpServlet {
    BrandService brandService = new BrandService();
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        List<Brand> brands =   brandService.selectAll();
        request.setAttribute("brands",brands);
        int curpage = 1; //默认是第1页
        int pageSize = 10; //默认分页大小为10
        String currentPage = request.getParameter("currentPage");
        if(currentPage!=null){
            curpage = Integer.valueOf(currentPage);
        }
//2.调用 BrandService 的selectAllPage方法进行业务逻辑处理，并接收返回的结果
        PageBean<Brand> pageBean = brandService.selectAllPage(curpage, pageSize);
//3.返回的结果存储到 request 域对象中
        request.setAttribute("pageBean",pageBean);

        request.getRequestDispatcher("/brand.jsp").forward(request,response);

    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);




    }
}
